using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spinning.Spinning.Entity;
using Spinning.Spinning.Interface;
using Microsoft.Xna.Framework;
using Spinning.Spinning.Unitity;
using Microsoft.Xna.Framework.Graphics;

namespace Spinning.Spinning.Scenes.ProcessScene.TopMembers
{
    class DirectionKey : AnimationSprite, ITouchable
    {
        MemberContainer Mc;

        public enum Direction
        {
            Right,
            Left
        }

        public Direction direction;

        public DirectionKey(MemberContainer mc)
        {
            Mc = mc;
            textureName = "item_store/direction_key";
        }
        bool isEnd;
        public bool IsEnd
        {
            get
            {
                return isEnd;
            }
            set
            {
                isEnd = value;
                if (isEnd)
                {
                    SetChangeFrameAnimation(new int[] { 1 });
                }
                else
                {
                    SetChangeFrameAnimation(new int[] { 0 });
                }
            }
        }

        public override void OnLoad()
        {
            base.OnLoad();
            ZIndex = Constants.ui;
            SetAnimation(new Point(2, 1));
            IsEnd = false;
        }

        protected override void UpdateSelf(GameTime gameTime)
        {
            base.UpdateSelf(gameTime);
            if (direction == Direction.Right)
                DrawEffect = SpriteEffects.FlipHorizontally;
            else
                DrawEffect = SpriteEffects.None;
        }

        public bool Contain(Microsoft.Xna.Framework.Vector2 _position)
        {
            Vector2 position = Vector2.Transform(_position, UnProjection);
            Vector2 topLeft = Position - Origin * new Vector2(_texture.Width, _texture.Height);
            Vector2 rightDown = topLeft + new Vector2(_texture.Width, _texture.Height);
            bool h = (position.X > topLeft.X && position.X < rightDown.X && position.Y > topLeft.Y && position.Y < rightDown.Y);
            return h;
        }

        public void OnTouch(Microsoft.Xna.Framework.Input.Touch.TouchLocation touchLocation)
        {
            Mc.OnKeyTouch(direction);
        }

        public void OnRelease(Microsoft.Xna.Framework.Input.Touch.TouchLocation touchLocation)
        {
           
        }
  
        public void OnHold(Microsoft.Xna.Framework.Input.Touch.TouchLocation touchLocation)
        {
        }
    }
}
